<template>
  <div class="main">
    <div class="title">新用户注册</div>
    <el-form :model="user" label-width="120px">
      <el-form-item label="用户名">
        <el-input v-model="user.name" />
      </el-form-item>
      <el-form-item label="性别">
        <el-radio-group v-model="user.sex">
          <el-radio label="男" value="男" />
          <el-radio label="女" value="女" />
        </el-radio-group>
      </el-form-item>
      <el-form-item label="地区">
        <el-select v-model="user.addr" placeholder="请选择你的地区">
          <el-option label="上海" value="上海" />
          <el-option label="北京" value="北京" />
        </el-select>
      </el-form-item>
      <el-form-item label="爱好">
        <el-checkbox-group v-model="user.hobby">
          <el-checkbox label="篮球" name="type" />
          <el-checkbox label="羽毛球" name="type" />
          <el-checkbox label="足球" name="type" />
          <el-checkbox label="网球" name="type" />
        </el-checkbox-group>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">注册</el-button>
        <el-button type="primary" @click="back">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>


<script>
/* eslint-disable */
import { ElMessageBox } from 'element-plus'
import axios from 'axios'

export default {
  name: 'register',

  data() {
    return {
      user: {}
    }
  },
  methods: {
    onSubmit() {
      console.log("输出输入源---->>>", this.user)
      axios.post('http://localhost:8001/vue/user/saveUser', JSON.stringify(this.user), {
        headers: {
          'Content-Type': 'application/json;charset=UTF-8',//设置请求头请求格式为JSON
        },
      }).then(
        (res) => {
          ElMessageBox.alert('用户注册', '注册成功', {
            confirmButtonText: 'OK',
          })
        }
      )

      // alert("注册成功！！！")
    },
    back(){
      this.$router.back()
    }
  }
}

</script>

<style>
.title {
  font-size: large;
  width: 100px;
  margin: 10px auto;
}

.main {
  text-align: center;
  border: 1px solid;
  border-radius: 5px;
  padding: 20px;
  width: 800px;
  margin: 100px auto;
}
</style>
